#!/opt/local/bin/perl
use strict;
use warnings;
use LastFM::API;

my $musicDir = shift ||  die "Usage: generateFlatFile.pl MusicDir e.g. ../Music\n";

my ($dataBase,$allTags) = getTagDatabase($musicDir);

open (OUTFILE,">flatFile.txt") || die "Can not create output file\n";

foreach my $file (sort keys %$dataBase){
  print OUTFILE "$file";
  foreach my $tag (sort keys %$allTags){
    if ($$dataBase{$file}{$tag}){
      print OUTFILE "\t$$dataBase{$file}{$tag}";
    }else { 
      print OUTFILE "\t";
    }
  }
  print OUTFILE "\n";
  }

